/**
 * B-JUI 源码打包
 * @author atuxe (atuxe@atuxe.com)
 */
module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    // Metadata.
    pkg: grunt.file.readJSON('package.json'),
    banner: '/*!\n * <%= pkg.name %> v<%= pkg.version %> (<%= pkg.homepage %>) ' +
      '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
      '<%= pkg.repository ? " * " + pkg.repository.name + "(" + pkg.repository.url + ")\\n" : "" %>' +
      ' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %> (<%= pkg.author.email %>).\n' +
      ' * Licensed under <%= pkg.licenses.type %> (<%= pkg.licenses.url %>)\n*/\n\n',
    // Task configuration.
    concat: {
      options: {
        banner: '',
        stripBanners: true
      },
      dist: {
        src: [
          'BJUI/js/bjui-core.js',
          'BJUI/js/bjui-regional.zh-CN.js',
          'BJUI/js/bjui-frag.js',
          'BJUI/js/bjui-extends.js',
          'BJUI/js/bjui-basedrag.js',
          'BJUI/js/bjui-slidebar.js',
          'BJUI/js/bjui-contextmenu.js',
          'BJUI/js/bjui-navtab.js',
          'BJUI/js/bjui-dialog.js',
          'BJUI/js/bjui-taskbar.js',
          'BJUI/js/bjui-ajax.js',
          'BJUI/js/bjui-alertmsg.js',
          'BJUI/js/bjui-pagination.js',
          'BJUI/js/bjui-util.date.js',
          'BJUI/js/bjui-datepicker.js',
          'BJUI/js/bjui-ajaxtab.js',
          'BJUI/js/bjui-tablefixed.js',
          'BJUI/js/bjui-tabledit.js',
          'BJUI/js/bjui-spinner.js',
          'BJUI/js/bjui-lookup.js',
          'BJUI/js/bjui-tags.js',
          'BJUI/js/bjui-upload.js',
          'BJUI/js/bjui-theme.js',
          'BJUI/js/bjui-initui.js',
          'BJUI/js/bjui-plugins.js'
        ],
        dest: 'dist/<%= pkg.filename %>.js'
      }
    },
    uglify: {
      options: {
        banner: '<%= banner %>'
      },
      dist: {
        src: '<%= concat.dist.dest %>',
        dest: 'dist/<%= pkg.filename %>.min.js'
      }
    },
    jshint: {
      options: {
        asi: true,
        curly: true,
        eqeqeq: true,
        immed: true,
        latedef: true,
        newcap: true,
        noarg: true,
        sub: true,
        undef: true,
        unused: true,
        boss: true,
        eqnull: true,
        browser: true,
        globals: {
          jQuery: true
        }
      },
      gruntfile: {
        src: 'Gruntfile.js'
      },
      lib_test: {
        src: '<%= concat.dist.dest %>'
      }
    },
    qunit: {
      files: ['test/**/*.html']
    },
    watch: {
      gruntfile: {
        files: '<%= jshint.gruntfile.src %>',
        tasks: ['jshint:gruntfile']
      },
      lib_test: {
        files: '<%= jshint.lib_test.src %>',
        tasks: ['jshint:lib_test', 'qunit']
      }
    }
  });

  // These plugins provide necessary tasks.
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-qunit');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-watch');

  // Default task.
  grunt.registerTask('default', [
    // 'jshint', 
    // 'qunit', 
    'concat', 
    'uglify'
  ]);

};
